from rest_framework import serializers

from goods.models import GoodsVisitCount, SKU, SKUSpecification, SPUSpecification, SPU, SKUImage
from orders.models import OrderInfo
from users.models import User


class GoodsSerializer(serializers.ModelSerializer):
    '''商品序列化器'''
    category = serializers.StringRelatedField(read_only=True)

    class Meta:
        model = GoodsVisitCount
        fields = ('count', 'category')


class UserSerializer(serializers.ModelSerializer):
    '''用户序列化器'''
    class Meta:
        model = User
        fields = ('id', 'username', 'mobile', 'email')


class SpecSerializer(serializers.ModelSerializer):
    '''SKU规格表'''
    spu = serializers.StringRelatedField(read_only=True)
    spu_id = serializers.IntegerField()

    class Meta:
        model = SPUSpecification
        fields = '__all__'


class SPUSerializer(serializers.ModelSerializer):
    '''SPU商品表序列化器'''
    class Meta:
        model = SPU
        fields = '__all__'


class SKUImageSerializer(serializers.ModelSerializer):
    '''图片序列化器'''
    sku = serializers.PrimaryKeyRelatedField(read_only=True)

    class Meta:
        model = SKUImage
        fields = ('sku', 'image', 'id')


class SKUSerializer(serializers.ModelSerializer):
    '''SPU商品表序列化器'''
    class Meta:
        model = SKU
        fields = ('id',)


class OrderSerializer(serializers.ModelSerializer):

    class Meta:
        model = OrderInfo
        fields = '__all__'

